package com.nd.mobile.study.view.helper;

import android.content.Context;
import android.widget.Toast;

public class ToastHelper {

	private static Toast	toast;

	/**
	 * 显示Toast 显示duration为short
	 * 
	 * @param context
	 * @param str
	 */
	public static void displayToast(Context context, String str) {
		prepare(context);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setText(str);
		toast.show();
	}

	/**
	 * 显示Toast 显示duration为long
	 * 
	 * @param context
	 * @param str
	 */
	public static void displayToastLong(Context context, String str) {
		prepare(context);
		toast.setDuration(Toast.LENGTH_LONG);
		toast.setText(str);
		toast.show();
	}

	/**
	 * 显示Toast 显示duration为short
	 * 
	 * @param context
	 * @param resourceId
	 */
	public static void displayToast(Context context, int resourceId) {
		String str = context.getResources().getString(resourceId);
		displayToast(context, str);
	}

	/**
	 * 显示Toast 显示duration为long
	 * 
	 * @param context
	 * @param resourceId
	 */
	public static void displayToastLong(Context context, int resourceId) {
		String str = context.getResources().getString(resourceId);
		displayToastLong(context, str);
	}

	private static void prepare(Context context) {
		if (null == toast) {
			toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
		}
	}

	public static void clear() {
		if (null != toast) {
			toast.cancel();
		}
	}
}
